package com.devmindset.legoframework.usage.client.util;

import java.util.ArrayList;
import java.util.List;

import com.devmindset.legoframework.usage.client.model.CalEvent;
import com.devmindset.legoframework.usage.client.model.Country;
import com.devmindset.legoframework.usage.client.model.OrderItem;
import com.devmindset.legoframework.usage.client.records.CountryRecord;
import com.devmindset.legoframework.usage.client.records.OrderItemRecord;
import com.devmindset.legoframework.usage.client.text.InitValues;
import com.smartgwt.client.widgets.calendar.CalendarEvent;

/**
 * Client-side utility service.
 * 
 * @author <a href="ice.penov@devmindset.com">Ice Penov</a>
 */
public final class Util {
	
	private Util() {}
	
	/**
	 * Retrieves the banner info models
	 * defined in outside Init.properties file.
	 *  
	 * @return the list of banner infos
	 */
	public static List<BannerInfo> getBanners() {
		List<BannerInfo> banners = new ArrayList<BannerInfo>();
		String bannerInfo = InitValues.get().banners();
		String[] bannerInfos = bannerInfo.split("\\|");
		for(String info : bannerInfos) {
			banners.add(new BannerInfo(info));
		}
		return banners;
	}

	public static List<CountryRecord> toCountryRecords(List<Country> list) {
		List<CountryRecord> result = new ArrayList<CountryRecord>();
		for (Country country : list) {
			CountryRecord record = new CountryRecord();
			record.setArea(country.getArea());
			record.setArticle(country.getArticle());
			record.setCapital(country.getCapital());
			record.setContinent(country.getContinent());
			record.setCountryCode(country.getCountryCode());
			record.setCountryName(country.getCountryName());
			record.setGdp(country.getGdp());
			record.setGovernment(country.getGovernment());
			record.setGovernmentDesc(country.getGovernmentDesc());
			record.setIndependence(country.getIndependence());
			record.setMemberG8(country.isMemberG8());
			record.setPopulation(country.getPopulation());			
			result.add(record);
		}
		return result;
	}

	public static List<OrderItemRecord> toOrderItemRecords(List<OrderItem> list) {
		List<OrderItemRecord> result = new ArrayList<OrderItemRecord>();
		for (OrderItem item : list) {
			OrderItemRecord record = new OrderItemRecord(item.getPk(), 
					item.getOrderID(), item.getItemDescription(), 
					item.getCategory(), item.getShipDate(), item.getQuantity(), item.getUnitPrice());
			result.add(record);
		}
		return result;
	}
	
	public static List<CalendarEvent> toCalendarEvents(List<CalEvent> list) {
		List<CalendarEvent> result = new ArrayList<CalendarEvent>();
		for (CalEvent calEvent : list) {
			CalendarEvent event = new CalendarEvent(calEvent.getEventId(), calEvent.getName(), 
					calEvent.getDescription(), calEvent.getStartDate(), calEvent.getEndDate());
			result.add(event);
		}
		return result;
	}
	
}